﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProcessRouteItem" :model="stateProcessRouteItem.vmModel" label-width="100px">
      <el-row>


				<el-col :xs="24" :lg="24" class="mb20">
					<el-form-item ref="Entity_Pos_FormItem" prop="Entity.Pos"  :label="$t('message.autotrans._Model_ProcessRouteItem_Pos')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_Pos')}), trigger: 'blur' }]" >
						<el-input-number v-model="stateProcessRouteItem.vmModel.Entity.Pos" clearable></el-input-number>
					</el-form-item>

				</el-col>

				<el-col :xs="24" :lg="24" class="mb20">
					<el-form-item ref="Entity_EquipmentId_FormItem"  prop="Entity.EquipmentId" :label="$t('message.autotrans._Model_ProcessRouteItem_EquipmentId')">
						<!--            <el-input v-model="stateProcessRouteItem.vmModel.Entity.EquipmentId" clearable></el-input>-->

						<el-select v-model="stateProcessRouteItem.vmModel.Entity.EquipmentId" @change="onEquipmentChange"  disabled clearable >
							<el-option v-for="item in stateProcessRouteItem.AllEquipments" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
						</el-select>
					</el-form-item>

				</el-col>



				<el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_RoutieId_FormItem" prop="Entity.RoutieId" :label="$t('message.autotrans._Model_ProcessRouteItem_Routie')">
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.RoutieId" clearable>
               <el-option v-for="item in stateProcessRouteItem.AllRouties" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_GroupCode_FormItem" prop="Entity.GroupCode" :label="$t('message.autotrans._Model_ProcessRouteItem_GroupCode')">
            <el-input v-model="stateProcessRouteItem.vmModel.Entity.GroupCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_OpCode_FormItem" prop="Entity.OpCode" :label="$t('message.autotrans._Model_ProcessRouteItem_OpCode')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_OpCode')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessRouteItem.vmModel.Entity.OpCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_OpName_FormItem" prop="Entity.OpName" :label="$t('message.autotrans._Model_ProcessRouteItem_OpName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_OpName')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessRouteItem.vmModel.Entity.OpName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_OpType_FormItem" prop="Entity.OpType" :label="$t('message.autotrans._Model_ProcessRouteItem_OpType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_OpType')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.OpType" clearable>
               <el-option key="Assembling" value="Assembling" :label="$t('message.autotrans._Enum_OpTypeEnum_Assembling')"></el-option>
               <el-option key="Detection" value="Detection" :label="$t('message.autotrans._Enum_OpTypeEnum_Detection')"></el-option>
               <el-option key="Rework" value="Rework" :label="$t('message.autotrans._Enum_OpTypeEnum_Rework')"></el-option>
               <el-option key="TakePartInOrOut" value="TakePartInOrOut" :label="$t('message.autotrans._Enum_OpTypeEnum_TakePartInOrOut')"></el-option>
               <el-option key="Weild" value="Weild" :label="$t('message.autotrans._Enum_OpTypeEnum_Weild')"></el-option>
               <el-option key="PrintMark" value="PrintMark" :label="$t('message.autotrans._Enum_OpTypeEnum_PrintMark')"></el-option>
               <el-option key="Fds" value="Fds" :label="$t('message.autotrans._Enum_OpTypeEnum_Fds')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_ErpOpCode_FormItem" prop="Entity.ErpOpCode" :label="$t('message.autotrans._Model_ProcessRouteItem_ErpOpCode')">
            <el-input v-model="stateProcessRouteItem.vmModel.Entity.ErpOpCode" clearable></el-input>
        </el-form-item>

        </el-col>

        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_PolicyCheckPrevProc_FormItem" prop="Entity.PolicyCheckPrevProc" :label="$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckPrevProc')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckPrevProc')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.PolicyCheckPrevProc" clearable>
               <el-option key="None" value="None" :label="$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_None')"></el-option>
               <el-option key="Worked" value="Worked" :label="$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_Worked')"></el-option>
               <el-option key="WorkedAndOK" value="WorkedAndOK" :label="$t('message.autotrans._Enum_PolicyCheckPrevProcEnum_WorkedAndOK')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_PolicyCheckProcBom_FormItem" prop="Entity.PolicyCheckProcBom" :label="$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckProcBom')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckProcBom')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.PolicyCheckProcBom" clearable>
               <el-option key="None" value="None" :label="$t('message.autotrans._Enum_PolicyCheckProcBomEnum_None')"></el-option>
               <el-option key="Over" value="Over" :label="$t('message.autotrans._Enum_PolicyCheckProcBomEnum_Over')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_PolicyCheckProcess_FormItem" prop="Entity.PolicyCheckProcess" :label="$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckProcess')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_PolicyCheckProcess')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.PolicyCheckProcess" clearable>
							<el-option key="None" value="None" :label="$t('message.autotrans._Enum_PolicyCheckProcBomEnum_None')"></el-option>
               <el-option key="AllowedEntryRepeat" value="AllowedEntryRepeat" :label="$t('message.autotrans._Enum_PolicyCheckProcessEnum_AllowedEntryRepeat')"></el-option>
               <el-option key="CheckBOMSource" value="CheckBOMSource" :label="$t('message.autotrans._Enum_PolicyCheckProcessEnum_CheckBOMSource')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_CtlAttr_FormItem" prop="Entity.CtlAttr" :label="$t('message.autotrans._Model_ProcessRouteItem_CtlAttr')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_CtlAttr')}), trigger: 'blur' }]" >
            <el-select v-model="stateProcessRouteItem.vmModel.Entity.CtlAttr" clearable>
               <el-option key="Must" value="Must" :label="$t('message.autotrans._Enum_ProcCtlAttrEnum_Must')"></el-option>
               <el-option key="Optional" value="Optional" :label="$t('message.autotrans._Enum_ProcCtlAttrEnum_Optional')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>

        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Etag_FormItem" prop="Entity.Etag" :label="$t('message.autotrans._Model_ProcessRouteItem_Etag')">
            <el-input v-model="stateProcessRouteItem.vmModel.Entity.Etag" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_ProcessRouteItem_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessRouteItem_Active')}), trigger: 'blur' }]" >
            <el-switch v-model="stateProcessRouteItem.vmModel.Entity.Active" clearable></el-switch>
        </el-form-item>

        </el-col>
				<el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_StdOpDuration_FormItem"  prop="Entity.StdOpDuration"
												:label="$t('message.autotrans._Model_ProcessRouteItem_StdOpDuration')"   >

						<el-input-number v-model="stateProcessRouteItem.vmModel.Entity.StdOpDuration" clearable></el-input-number>
					</el-form-item>

				</el-col>
				<el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_StdPrepDuration_FormItem"  prop="Entity.StdPrepDuration" :label="$t('message.autotrans._Model_ProcessRouteItem_StdPrepDuration')">
						<el-input-number v-model="stateProcessRouteItem.vmModel.Entity.StdPrepDuration" clearable></el-input-number>
					</el-form-item>

				</el-col>
      </el-row>

      <el-tabs type="border-card" >
        <el-tab-pane :label="$t('message.autotrans.Page工序参数')" key="工序参数">
          <WtmTable ref="tableRefProcessParameterOpList" v-bind="tableDataProcessParameterOpList" v-model="stateProcessRouteItem.vmModel.Entity.ProcessParameter_Op"></WtmTable>
        </el-tab-pane>

        <el-tab-pane :label="$t('message.autotrans.Page工序数据')" key="工序数据">
          <WtmTable ref="tableRefProcessResultsOpList" v-bind="tableDataProcessResultsOpList" v-model="stateProcessRouteItem.vmModel.Entity.ProcessResults_Op"></WtmTable>
        </el-tab-pane>

      </el-tabs>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitProcessRouteItem"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseProcessRouteItem"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProcessManagementProcessRouteItemEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick, onBeforeMount } from 'vue';
import { processrouteitemApi } from '/@/api/processmanagement/processrouteitem';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 使用defineProps声明属性
const props = defineProps({
	wtmdata: {
		type: Object,
		default: () => ({})
	}
});

// 定义变量内容
const formRefProcessRouteItem = ref();
const stateProcessRouteItem = reactive({
	vmModel: {
		Entity:{
			RoutieId: null,
			GroupCode: '',
			OpCode: '',
			OpName: '',
			OpType: undefined,
			ErpOpCode: '',
			StdOpDuration: null,
			StdPrepDuration: null,
			PolicyCheckPrevProc: undefined,
			PolicyCheckProcBom: undefined,
			PolicyCheckProcess: undefined,
			CtlAttr: undefined,
			Pos: null,
			Etag: '',
			Active: undefined,
			EquipmentId: null,
			EquipmentCode: '',
			    ProcessParameter_Op:[],
        ProcessResults_Op:[],
			ID:null,
		},

	},

	AllEquipments:[] as any[],
	AllRouties: [] as any[],
	AllOps: [] as any[],
	AllParaTags: [] as any[],
	AllResultTags: [] as any[],
	EquipId:0
});

// 定义变量内容
const tableRefProcessParameterOpList = ref();
const tableDataProcessParameterOpList = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
		{title:ci.proxy.$t('message.autotrans.Page参数名称'),key: 'ParameterName',type: 'textbox',isCheck: true},
		{title:ci.proxy.$t('message.autotrans.Page数据类型'),key: 'DataType',type: 'combobox',colWidth:150,comboData:{
				Sys_Bit:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Bit'),
				Sys_Byte:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Byte'),
				Sys_Word:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Word'),
				Sys_DWord:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DWord'),
				Sys_Int:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Int'),
				Sys_DInt:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DInt'),
				Sys_Real:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Real'),
				Sys_LReal:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_LReal'),
				Sys_String:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_String'),},isCheck: true},
     {title:ci.proxy.$t('message.autotrans.Page变量'),key: 'TagId',type: 'combobox',colWidth:150,comboData:`/api/ProcessManagement/ProcessParameter/GetByEquipmentTags?id=${props.wtmdata.ProcessRouteItem_EquipmentId}`,isCheck: true},
      // {title:ci.proxy.$t('message.autotrans.Page变量名称'),key: 'TagName',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设定值'),key: 'SetValue',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page精度'),key: 'Precision',type: 'textbox',defaultValue:3,isCheck: true},
  {title:ci.proxy.$t('message.autotrans.Page采取方式'),key: 'SampleMode',type: 'combobox',comboData:{
                SingleData:ci.proxy.$t('message.autotrans._Enum_DataSampleEnum_SingleData'),
                TimeCollection:ci.proxy.$t('message.autotrans._Enum_DataSampleEnum_TimeCollection'),          
               },isCheck: true},       
       { title: ci.proxy.$t('message.autotrans.Page采取频率'), key: 'IntervalSeconds', defaultValue:0,type: 'number', isCheck: true, sortable: 'custom', colWidth: 180 },  
      {title:ci.proxy.$t('message.autotrans.Page激活'),key: 'Active',type: 'switch',defaultValue:true,comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck:true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});

// 定义变量内容
const tableRefProcessResultsOpList = ref();
const tableDataProcessResultsOpList = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
		{title:ci.proxy.$t('message.autotrans.Page数据名称'),key: 'DataName',type: 'textbox',colWidth:150,isCheck: true},
		{title:ci.proxy.$t('message.autotrans.Page变量'),key: 'TagId',type: 'combobox',colWidth:150,comboData:`/api/ProcessManagement/ProcessResults/GetByEquipmentTags?id=${props.wtmdata.ProcessRouteItem_EquipmentId}`,isCheck: true},
      // {title:ci.proxy.$t('message.autotrans.Page变量'),key: 'TagId',type: 'textbox',isCheck: true},
      // {title:ci.proxy.$t('message.autotrans.Page变量名称'),key: 'TagName',type: 'textbox',isCheck: true},

      {title:ci.proxy.$t('message.autotrans.Page单位'),key: 'Unit',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page上限'),key: 'UpperLimit',type: 'number',colWidth:180,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page下限'),key: 'LowerLimit',type: 'number',colWidth:180,isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page激活上下限'),key: 'ActiveLimit',type: 'switch',colWidth:150,comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});




// 取消
const onCloseProcessRouteItem = () => {
    closeDialog();
};

//当设备选择时
const onEquipmentChange = (equid:any) =>
{

	if (equid){
		other.getSelectList(`/api/ProcessManagement/ProcessParameter/GetByEquipmentTags?id=${equid}`,[],false).then(x=>{stateProcessRouteItem.AllParaTags = x});
		other.getSelectList(`/api/ProcessManagement/ProcessResults/GetByEquipmentTags?id=${equid}`,[],false).then(x=>{stateProcessRouteItem.AllResultTags = x});

	}


}




// 提交
const onSubmitProcessRouteItem = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProcessRouteItem.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            processrouteitemApi().edit(stateProcessRouteItem.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};



// 页面加载时
onMounted(() => {

	// stateProcessRouteItem.EquipId=props.wtmdata.ProcessRouteItem_EquipmentId;
	// other.getSelectList(`/api/ProcessManagement/ProcessParameter/GetByEquipmentTags?id=${stateProcessRouteItem.EquipId}`,[],false).then(x=>{stateProcessRouteItem.AllParaTags = x});
	// other.getSelectList(`/api/ProcessManagement/ProcessResults/GetByEquipmentTags?id=${stateProcessRouteItem.EquipId}`,[],false).then(x=>{stateProcessRouteItem.AllResultTags = x});


	other.getSelectList('/api/EquipmentManagement/EquipAlarmRecord/GetEquipments',[],false).then(x=>{stateProcessRouteItem.AllEquipments = x});
    other.getSelectList('/api/ProcessManagement/ProcessRouteItem/GetProcessRoutes',[],false).then(x=>{stateProcessRouteItem.AllRouties = x});

		if (props.wtmdata) {
		stateProcessRouteItem.vmModel.Entity.ID = props.wtmdata.ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProcessRouteItem.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
    
	processrouteitemApi().get(stateProcessRouteItem.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProcessRouteItem.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

